import 'reflect-metadata'
import { CJDBUtil } from '../db/CJDBUtil';
import { AnnotationEnum } from './AnnotationEnum';
import { TableStructCache } from '../db/TableStructCache';

const TAG = "CJDBUtil"

export const Table = (tableName?: string): ClassDecorator => (target: any) => {

  let tbName = target.name
  if (tableName) {
    tbName = tableName
  }
  target.prototype[AnnotationEnum.TABLE] = tbName;
  Reflect.defineMetadata(AnnotationEnum.TABLE, tbName, target);
  // Reflect.defineMetadata('Table', tableName, target, 'objects');

  // CJLogUtil.info(TAG, "constructor.arguments：" + JSON.stringify(target.constructor.arguments))
  // CJLogUtil.info(TAG, "table cache has：" + TableStructCache.maps.has(tableName))
  if (!TableStructCache.tableMaps.has(target.name)) {
    TableStructCache.tableMaps.set(target.name, tbName)
  }
  // CJLogUtil.info(TAG, "TableStructCache Tables：" + JSON.stringify(TableStructCache.tableMaps.get(target.name)))
};
